
version 15
capture log close
set more off
clear
clear matrix
clear mata

if c(username)=="WB485280" {
		glo rootdir		"C:\Users\wb485280\OneDrive - WBG\radicalization"
		}
if c(username)=="WB382635" {
		glo rootdir		"C:\Users\wb382635\Dropbox\Unemp & daesh"
		}
if c(username)=="WB452275" {
		glo rootdir		"C:\Users\WB452275\Dropbox\Projects\Unemp & daesh"
		}
if c(username)=="sarurchaudhary" {
		glo rootdir		"/Users/sarurchaudhary/Dropbox/Unemp & daesh"
		}
if c(username)=="kartikabhatia" {
			glo rootdir		"/Users/kartikabhatia/Dropbox/Before2019/Unemp & daesh"
			}
			
		glo	datadir     "${rootdir}/Data/Raw data"
		glo outdir		"${rootdir}/Data/Working datasets"
		glo dodir		"${rootdir}/Dofiles"
        
		cd "${outdir}"
		
log using isis_CE_prep, replace t


* ------------------------------------------------------------------------------
* Date : July 2017 [chkd oct 2021]


* Project : Mena Economic Monitor, Working Paper (MNACE, The World Bank)


* This do file prepares the ISIS fighters database by education status for merge

* Database used : ISIS_fighters.dta.dta


* Output : isis_CE.dta

* ------------------------------------------------------------------------------

*                      ----------------------------------
*                      --------ISIS fighters Data--------
*                      ----------------------------------


use "${datadir}/ISIS_fighters_new.dta", clear
drop if Country_resid ==""    //Use only fighters with non-missing country of residence

*           =================
*           Variables to keep
*           =================

* Creating no. of fighters per country of residence

sort Country_resid, stable
gen id=_n

* Creating no. of fighters by education levels per country of residence

rename Education isis_education
recode isis_education (1=1) (2=1) (3=1) (4=2) (5=2) (6=3) (7=4)
label define ed 1 "primary/noeduc" 2 "secondary" 3 "tertiary" 4 "missing_educ"
label values isis_education ed
egen nisis_educ= count(id), by (Country_resid isis_education)
label variable nisis_educ "no. of fighters by education levels per country of residence " 

* Creating additional ISIS variables to be collapsed by country education

	g Married=.
		replace Married=1 if CivilStatus=="Married"
		replace Married=0 if CivilStatus=="Divorced" | CivilStatus=="Single"
		
	g Parent=.
		replace Parent=1 if Number_children>0 & !missing(Number_children)
		replace Parent=0 if Number_children==0 | missing(Number_children)

	g ReligiousPlus=.
		replace ReligiousPlus=1 if ReligiousLevel=="Advanced"
		replace ReligiousPlus=1 if ReligiousLevel=="Intermediary"
		replace ReligiousPlus=0 if ReligiousLevel=="Basic"

	g AdminAspiration=.
		replace AdminAspiration=1 if Aspiration=="Administrative"
		replace AdminAspiration=0 if Aspiration=="Fighters"
		replace AdminAspiration=0 if Aspiration=="Suicid_fighter"
		replace AdminAspiration=0 if Aspiration=="Suicide"

	g FighterAspiration=.
		replace FighterAspiration=0 if Aspiration=="Administrative"
		replace FighterAspiration=1 if Aspiration=="Fighters"
		replace FighterAspiration=0 if Aspiration=="Suicid_fighter"
		replace FighterAspiration=0 if Aspiration=="Suicide"

	g SuicideAspiration=.
		replace SuicideAspiration=0 if Aspiration=="Administrative"
		replace SuicideAspiration=0 if Aspiration=="Fighters"
		replace SuicideAspiration=1 if Aspiration=="Suicid_fighter"
		replace SuicideAspiration=1 if Aspiration=="Suicide"

	g PreviousJihad=.
		replace PreviousJihad=0 if Experience=="No"
		replace PreviousJihad=1 if Experience=="Yes"
		
	g PreviousJobSkilled_1=.
		replace PreviousJobSkilled_1=0 if inlist(job,2,3)==0 
		replace PreviousJobSkilled_1=1 if inlist(job,2,3)==1 //Manager; Professional Worker
	
	g PreviousJobSkilled_2=.
		replace PreviousJobSkilled_2=0 if inlist(job,2,3,7,8,9)==0 
		replace PreviousJobSkilled_2=1 if inlist(job,2,3,7,8,9)==1 //Manager; Professional Worker;Shop owner; Govt Employee; Pvt employee
	

    g nisis_admin   =AdminAspiration 
    g nisis_fighter =FighterAspiration 
    g nisis_suicide =SuicideAspiration

label variable nisis_admin   "no. of aspiring administrators by education levels per country of residence " 
label variable nisis_fighter "no. of aspiring fighters by education levels per country of residence " 
label variable nisis_suicide "no. of aspiring suicide fighters by education levels per country of residence " 

* ------------------------------------------------------------------------------

* Collapsing data to create country level estimates (keeping the same labels)


foreach v of var nisis_educ nisis_admin nisis_fighter nisis_suicide {
 	local l`v' : variable label `v'
        if `"`l`v''"' == "" {
 		local l`v' "`v'"
  	}
  }
	collapse  (max) nisis_educ (rawsum) nisis_admin (rawsum) nisis_fighter (rawsum) nisis_suicide  (mean)age Married Parent ReligiousPlus AdminAspiration FighterAspiration SuicideAspiration PreviousJihad PreviousJobSkilled_1 PreviousJobSkilled_2, by(Country_resid isis_education)


 foreach v of var nisis_educ nisis_admin nisis_fighter nisis_suicide {
 	label var `v' "`l`v''"
 }

 
* ------------------------------------------------------------------------------


* Adding countries that are in WDI but not in ISIS database (for merge)

sort Country_resid, stable
gen country_temp=Country_resid
gen year=2013

 replace country_temp="Bosnia and Herzegovina" if country_temp=="Bosnia"
 replace country_temp="Bulgaria" if country_temp=="Bulgary"
 replace country_temp="Cameroon" if country_temp=="Cameroun"
 replace country_temp="Egypt, Arab Rep." if country_temp=="Egypt"
 replace country_temp="Hong Kong SAR, China" if country_temp=="Hong Kong"
 replace country_temp="Iran, Islamic Rep." if country_temp=="Iran"
 replace country_temp="Kyrgyz Republic" if country_temp=="Kyrgyzstan"
 replace country_temp="Lao PDR" if country_temp=="Laos"
 replace country_temp="Macedonia, FYR" if country_temp=="Macedonia"
 replace country_temp="Russian Federation" if country_temp=="Russia"
 replace country_temp="Slovak Republic" if country_temp=="Slovakia"
 replace country_temp="Syrian Arab Republic" if country_temp=="Syria"
 replace country_temp="Trinidad and Tobago" if country_temp=="Trinidad"
 replace country_temp="Venezuela, RB" if country_temp=="Venezuela"
 replace country_temp="Yemen, Rep." if country_temp=="Yemen"
 
 insobs 111, before(1)
 replace country_temp = "Angola" in 1
 replace year = 2013 in 1
 replace country_temp = "Argentenia" in 2
 replace year = 2013 in 2
 replace country_temp = "Armenia" in 3
 replace year = 2013 in 3
 replace country_temp = "Bangladesh" in 4
 replace year = 2013 in 4
 replace country_temp= "Belarus" in 5
 replace year = 2013 in 5
 replace country_temp= "Belize" in 6
 replace year = 2013 in 6
 replace country_temp = "Benin" in 7
 replace year = 2013 in 7
 replace country_temp = "Bhutan" in 8
 replace year = 2013 in 8
 replace country_temp = "Bolivia" in 9
 replace year = 2013 in 9
 replace country_temp = "Botswana" in 10
 replace year = 2013 in 10
 replace country_temp = "Brazil" in 11
 replace year = 2013 in 11
 replace country_temp = "Burkina Faso" in 12
 replace year = 2013 in 12
 replace country_temp = "Burundi" in 13
 replace year = 2013 in 13
 replace country_temp= "Cambodia" in 14
 replace year = 2013 in 14
 replace country_temp = "Central African Republic" in 15
 replace year = 2013 in 15
 replace country_temp = "Chad" in 16
 replace year = 2013 in 16
 replace country_temp = "Chile" in 17
 replace year = 2013 in 17
 replace country_temp = "Colombia" in 18
 replace year = 2013 in 18
 replace country_temp = "Comoros" in 19
 replace year = 2013 in 19
 replace country_temp = "Congo Brazzaville" in 20
 replace year = 2013 in 20
 replace country_temp = "Congo Kinshasa" in 21
 replace year = 2013 in 21
 replace country_temp = "Costa Rica" in 22
 replace year = 2013 in 22
 replace country_temp = "Croatia" in 23
 replace year = 2013 in 23
 replace country_temp= "Cuba" in 24
 replace year = 2013 in 24
 replace country_temp = "Cyprus" in 25
 replace year = 2013 in 25
 replace country_temp = "Czech Republic" in 26
  replace year = 2013 in 26
 replace country_temp = "Djibouti" in 27
 replace year = 2013 in 27
 replace country_temp = "Dominican republic" in 28
 replace year = 2013 in 28
 replace country_temp = "Ecuador" in 29
 replace year = 2013 in 29
 replace country_temp = "El Salvador" in 30
 replace year = 2013 in 30
 replace country_temp = "Equatorial Guinea" in 31
 replace year = 2013 in 31
 replace country_temp = "Eritrea" in 32
 replace year = 2013 in 32
 replace country_temp = "Estonia" in 33
 replace year = 2013 in 33
 replace country_temp = "Ethiopia" in 34
 replace year = 2013 in 34
 replace country_temp = "Finland" in 35
 replace year = 2013 in 35
 replace country_temp = "Gabon" in 36
 replace year = 2013 in 36
 replace country_temp = "Gambia, The" in 37
 replace year = 2013 in 37
 replace country_temp = "Ghana" in 38
 replace year = 2013 in 38
replace country_temp = "Greece" in 39
 replace year = 2013 in 39
 replace country_temp = "Guatemala" in 40
 replace year = 2013 in 40
 replace country_temp = "Guinea" in 41
 replace year = 2013 in 41
 replace country_temp = "Guinea-Bissau" in 42
 replace year = 2013 in 42
 replace country_temp = "Guyana" in 43
 replace year = 2013 in 43
 replace country_temp = "Haiti" in 44
 replace year = 2013 in 44
 replace country_temp = "Honduras" in 45
 replace year = 2013 in 45
 replace country_temp = "Hong Kong" in 46
 replace year = 2013 in 46
 replace country_temp= "Hungary" in 47
 replace year = 2013 in 47
 replace country_temp = "Iceland" in 48
 replace year = 2013 in 48
  replace country_temp = "Israel" in 49
 replace year = 2013 in 49
 replace country_temp = "Italy" in 50
 replace year = 2013 in 50
 replace country_temp = "Ivory Coast" in 51
 replace year = 2013 in 51
 replace country_temp = "Jamaica" in 52
 replace year = 2013 in 52
 replace country_temp = "Japan" in 53
 replace year = 2013 in 53
 replace country_temp = "Laos" in 54
 replace year = 2013 in 54
 replace country_temp = "Latvia" in 55
 replace year = 2013 in 55
replace country_temp = "Lesotho" in 56
 replace year = 2013 in 56
 replace country_temp = "Liberia" in 57
 replace year = 2013 in 57
 replace country_temp = "Lithuania" in 58
 replace year = 2013 in 58
 replace country_temp = "Luxembourg" in 59
 replace year = 2013 in 59 
 replace country_temp = "Madagascar" in 60
 replace year = 2013 in 60
 replace country_temp = "Malawi" in 61
 replace year = 2013 in 61
 replace country_temp= "Mali" in 62
 replace year = 2013 in 62
 replace country_temp = "Malta" in 63
 replace year = 2013 in 63
replace country_temp = "Mauritius" in 64
 replace year = 2013 in 64
 replace country_temp = "Mexico" in 65
 replace year = 2013 in 65
 replace country_temp = "Moldova" in 66
 replace year = 2013 in 66
 replace country_temp = "Mongolia" in 67
 replace year = 2013 in 67
 replace country_temp = "Montenegro" in 68
 replace year = 2013 in 68
 replace country_temp = "Mozambique" in 69
 replace year = 2013 in 69
 replace country_temp = "Myanmar" in 70
 replace year = 2013 in 70
 replace country_temp = "Nagorno Karbakh" in 71
 replace year = 2013 in 71
 replace country_temp= "Namibia" in 72
 replace year = 2013 in 72
 replace country_temp = "Nepal" in 73
 replace year = 2013 in 73
 replace country_temp = "New Zealand" in 74
 replace year = 2013 in 74
 replace country_temp = "Nicargua" in 75
 replace year = 2013 in 75
 replace country_temp = "Niger" in 76
 replace year = 2013 in 76
 replace country_temp = "Nigeria" in 77
 replace year = 2013 in 77
 replace country_temp = "North Korea" in 78
 replace year = 2013 in 78
 replace country_temp = "Northern Cyprus" in 79
 replace year = 2013 in 79
 replace country_temp = "Oman" in 80
 replace year = 2013 in 80
 replace country_temp = "Panama" in 81
 replace year = 2013 in 81
 replace country_temp = "Paraguay" in 82
 replace year = 2013 in 82
 replace country_temp = "Peru" in 83
 replace year = 2013 in 83
 replace country_temp = "Philippines" in 84
 replace year = 2013 in 84
 replace country_temp= "Portugal" in 85
 replace year = 2013 in 85
 replace country_temp = "Puerto Rico" in 86
 replace year = 2013 in 86
 replace country_temp = "Romania" in 87
 replace year = 2013 in 87
 replace country_temp = "Rwanda" in 88
 replace year = 2013 in 88
 replace country_temp = "Senegal" in 89
 replace year = 2013 in 89
replace country_temp = "Sierra Leone" in 90
 replace year = 2013 in 90
 replace country_temp = "Singapore" in 91
 replace year = 2013 in 91
 replace country_temp = "Slovakia" in 92
 replace year = 2013 in 92
 replace country_temp = "Slovenia" in 93
 replace year = 2013 in 93
 replace country_temp = "Somaliland" in 94
 replace year = 2013 in 94
 replace country_temp = "South Korea" in 95
 replace year = 2013 in 95
 replace country_temp = "South Sudan" in 96
 replace year = 2013 in 96
 replace country_temp= "Sri Lanka" in 97
 replace year = 2013 in 97
  replace country_temp = "Suriname" in 98
 replace year = 2013 in 98
 replace country_temp = "Swaziland" in 99
 replace year = 2013 in 99
 replace country_temp = "Taiwan" in 100
 replace year = 2013 in 100
 replace country_temp = "Tanzania" in 101
 replace year = 2013 in 101
 replace country_temp = "Thailand" in 102
 replace year = 2013 in 102
 replace country_temp = "Togo" in 103
 replace year = 2013 in 103
replace country_temp= "Uganda" in 104
 replace year = 2013 in 104
 replace country_temp = "United Arab Emirates" in 105
 replace year = 2013 in 105
 replace country_temp = "Uruguay" in 106
 replace year = 2013 in 106
 replace country_temp = "Venezuela" in 107
 replace year = 2013 in 107
 replace country_temp = "Vietnam" in 108
 replace year = 2013 in 108
 replace country_temp = "Zambia" in 109
 replace year = 2013 in 109
 replace country_temp = "Zimbabwe" in 110
 replace year = 2013 in 110
 replace country_temp = "South Africa" in 111
 replace year = 2013 in 111
 	
  * Creating numeric variable for countries

sort  country_temp, stable
encode country_temp, gen(ctry)
drop country_temp


sort ctry year

save "${outdir}/isis_ver2.dta", replace

*****Cleaning up to create a panel (country-4education categories)

 * Creating a temp dataset to merge 

 use "${outdir}/isis_ver2.dta", clear
 
 drop nisis_educ nisis_admin nisis_fighter nisis_suicide isis_education Country_resid year age Married Parent ReligiousPlus AdminAspiration FighterAspiration SuicideAspiration PreviousJihad PreviousJobSkilled_1 PreviousJobSkilled_2
 duplicates drop
 save "${outdir}/test_", replace
 append using "${outdir}/test_"
 append using "${outdir}/test_"
 append using "${outdir}/test_"
 tab ctry
 gen isis_education = 1
 bys ctry: gen count = sum( isis_education )
 drop isis_education
 rename count isis_education
 sort ctry isis_education
 save "${outdir}/test_2", replace

 * Merge the temp data with the isis data
 use "${outdir}/isis_ver2.dta", clear
 merge 1:1 ctry isis_education using "${outdir}/test_2.dta"

drop if isis_education==.
replace year=2013 if year==.
drop _merge
sort ctry isis_education
rename age isis_age

save "${outdir}/isis_CE.dta", replace
















